<?php
//

//inputs:  fieldspec, listpage, 

class CF_Header{

var $refreshpage;
var $order_param = '_order';
var $dir_param = '_dir';
var $fieldspec;
var $extrastring;

	function CF_Header($fieldspec, $refreshpage, $extrastring = ''){
		__construct($fieldspec, &$thetable);
	}

	function __construct($fieldspec, $refreshpage, $extrastring = ''){
		$this->refreshpage = $refreshpage;
		$this->fieldspec = $fieldspec;
		$this->extrastring = $extrastring;
		//$this->multiselect = $this->thetable->multiselect;

	
	}
	
	function set_order_param($order_param){
		$this->order_param = $order_param;
	}
	
	function set_dir_param($dir_param){
		$this->dir_param = $dir_param;
	}

	/**
	 * make_simple_heading will return a heading row of the column name, in order of fieldspecs presented in fields definition
	 * @return string
	 */
	function make_simple_heading(){
		foreach($this->fieldspec AS $col_name => $colspec){
			$headtext .= '<th>';
			(empty($colspec['headname']))?$headtext .= $col_name: $headtext .= $colspec['headname'] . "</th>\n";
			}
		return $headtext;
	}

	/**
	 * make_sort_heading will return a heading where clicking on the colum name will sort by the column
	 * This requiresthe page to reload to sort the the column name through the variable specified by
	 * set_ordervar().  The return page is set in set_selfpage().
	 * @return string
	 */
	function make_sort_heading(){
		$headtext = '';
		if(is_array($this->fieldspec)){
		foreach($this->fieldspec AS $col_name => $colspec){
			if(!empty($colspec['show'])){
			$headtext .= '<th>';
			(empty($colspec['headname']))?$name = $col_name: $name = $colspec['headname'] . "</th>\n";
			
			if($colspec['sort'] == 1){
				$headtext .= "<a href=\"{$this->refreshpage}?{$this->order_param}=$col_name{$this->extrastring}\">$name</a>";
			}
			else{
				$headtext .= $name;
			}
			$headtext .= "</th>";
			} // end if shown
			}// end foreach
			}
								
		return $headtext;
	}	



}

?>
